package com.example.campus_order_sb.utils;

import com.example.campus_order_sb.enums.UserType;
import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

@Converter(autoApply = true)
public class UserTypeConverter implements AttributeConverter<UserType, String> {
    @Override
    public String convertToDatabaseColumn(UserType attribute) {
        if (attribute == null) {
            return null;
        }
        return attribute.name();  // 这会保持枚举值为大写
    }

    @Override
    public UserType convertToEntityAttribute(String dbData) {
        if (dbData == null) {
            return null;
        }
        return UserType.valueOf(dbData.toUpperCase());  // 转换为大写再查找枚举值
    }
}